home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15275 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  976 b 

  1. Path: hshlab-16.acadiau.ca!005523c
  2. From: 005523c@axe.acadiau.ca (Christina Chan)
  3. Newsgroups: comp.lang.c++
  4. Subject: Help : friend func' for template class
  5. Date: Thu, 4 Apr 1996 16:18:35 GMT
  6. Organization: Acadia University
  7. Message-ID: <005523c.8.3163F65B@axe.acadiau.ca>
  8. NNTP-Posting-Host: iceberg.acadiau.ca
  9. X-Newsreader: Trumpet for Windows [Version 1.0 Rev B.7]
  10.  
  11. Hi,
  12.  
  13. I am writing a friend function which overload operator<< for a template class 
  14. Bst, but I got a syntax problem, could anybody tell me the right syntax.
  15.  
  16.  
  17. Declaration : Bst.h
  18.     friend void printTree(ostream& s, (Bst<T>::node*) n);
  19.     friend ostream& operator<< (ostream& s, (Bst<T>&) b);
  20.  
  21.  
  22. Definition : Bst.cpp
  23.  
  24. void printTree(ostream& s, Bst<T>::node* n)
  25. // print a Binary Search Tree in preorder
  26. {
  27.     if ( n!=NULL )
  28.     {
  29.         printTree(n->lchild);
  30.         s << n->data;
  31.         s << '\n';
  32.         printTree(n->rchild);
  33.     }
  34. }
  35.  
  36. ostream& operator<< (ostream& s, Bst<T>& b)
  37. // Overload operator <<
  38. {
  39.     printTree(s, b.root);
  40.     return s;
  41. }
  42.  
  43.  
  44.